﻿Imports Sy.UI.Cef
Imports SyCefBrowser = Sy.UI.CefBrowser
Public Class Frm_Auth
    Private Property AuthUrl As String
    Private Property TokenUrl As String
    Private WithEvents ChromeBrowser As SyCefBrowser
    Private Sub Frm_Auth_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim Action = Sub()
                         InvokEx(Sub()
                                     ChromeBrowser = SyCefBrowser.LoadBrowser(Me, AuthUrl)
                                     Lab_Url.Text = AuthUrl
                                 End Sub)
                     End Sub
        Action.BeginInvoke(Null, Null)
    End Sub
    ''' <summary>
    ''' 重写页面显示方法 有返回值，返回值即为我们要的URL
    ''' </summary>
    ''' <param name="AuthUrl">参数为跳转链接</param>
    ''' <returns></returns>
    Public Overloads Function ShowDialog(AuthUrl As String) As String
        Me.AuthUrl = AuthUrl
        ShowDialog(Owner)
        Return TokenUrl
    End Function
    ''' <summary>
    ''' CEF加载结束 结束时可判断URL是不是我们要的URL，是就直接把返回值对象赋值上
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="DocumentCompletedEventArgs"></param>
    Private Sub ChromeBrowser_DocumentCompleted(sender As SyCefBrowser, DocumentCompletedEventArgs As DocumentCompletedEventArgs) Handles ChromeBrowser.DocumentCompleted
        Dim CurUrl As String = sender.Address
        If CurUrl.Contains("https://oauth.vk.com/blank.html") Then
            TokenUrl = CurUrl
        End If
    End Sub
    Private Sub ChromeBrowser_AddressChanged(sender As SyCefBrowser, url As String) Handles ChromeBrowser.AddressChanged
        Lab_Url.Text = url
        If url.Contains("https://oauth.vk.com/blank.html") Then
            TokenUrl = url
        End If
    End Sub


End Class